﻿Public Class frmEditSections 
    Dim Strsql As String
    Dim _Mysql As New ClsSQLhelper
    Dim On_Load As Boolean = True
    Public Primary_Key As Integer
    Public Section_ID As Integer
    Dim DS As New DataSet
#Region "Function"
    Sub Load_Data()
        Try
            Strsql = "Select * from section where section_id = " & Primary_Key
            Dim DT_Section As DataTable
            DT_Section = _Mysql.GetMYSQLDataTable(Strsql, "section")
            Me.Txtname.Text = DT_Section.Rows(0).Item("section_name").ToString
            Me.TxtNote.Text = DT_Section.Rows(0).Item("note").ToString
            Me.ChkActive.Checked = IIf(DT_Section.Rows(0).Item("active") = True, True, False)

        Catch ex As Exception

        End Try
    End Sub
#End Region
    Private Sub BtnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSave.Click
        Try
            Strsql = "update section set section_name= '" & Me.Txtname.Text & "', note = '" & Me.TxtNote.Text & "' ,active = " & Me.ChkActive.Checked
            Strsql = Strsql & " where section_id = " & Primary_Key

            _Mysql.MySQLExecute(Strsql)


            Strsql = "select * from  category where  sectionid = " & Primary_Key

            DS = _Mysql.GetMYSQLDataset(Strsql, "DS_category", "category")
            If DS.Tables(0).Rows.Count = 0 Then
                Strsql = "Insert into category (Category_name,note,siteid,sectionid) values ('ไม่ระบุ','ค่าเริ่มต้น'," & Primary_Key & ")"

                _Mysql.MySQLExecute(Strsql)
            End If



            MsgBox("ปรับปรุงข้อมูลเข้าเรียบร้อยแล้ว", MsgBoxStyle.Information)
            Me.DialogResult = Windows.Forms.DialogResult.OK
            Me.Dispose()
        Catch ex As Exception
            With frmDebug
                .lblFormName.Text = Me.Name
                .lblFunctionName.Text = "BtnSave_Click"
                .MemoErr_Description.Text = ex.Message
                .MemoSQL.Text = Strsql
                .ShowDialog()
            End With
        End Try
    End Sub

    Private Sub frmEditSections_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Load_Data()
    End Sub

    Private Sub BtnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCancel.Click
        Me.Dispose()
    End Sub
End Class